import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Parser {
    public static Map<String,String> parseInputFile(String filePath) throws IOException {
        File inputFile = new File(filePath);

        List<String> inputList = FileUtils.readLines(inputFile, "UTF-8");

        HashMap<String,String> inputMap = new HashMap<>();
        if (inputList.isEmpty()){
            return inputMap;
        }

        for (int i = 0; i < inputList.size(); i = i+2) {
            inputMap.put(inputList.get(i),inputList.get(i+1));
        }
        return inputMap;
    }

    public static String getUrlFromUserInput(Map<String ,String> inputMap){
        String url = inputMap.get(":scheme:")+"://"+inputMap.get(":authority:")+inputMap.get(":path:");
        inputMap.remove(":scheme:");
        inputMap.remove(":authority:");
        inputMap.remove(":path:");
        inputMap.remove(":method:");
        inputMap.put("accept-encoding:","gzip, deflate, zstd");
        return url;
    }
}
